package com.lx.main;

import com.lx.entity.Film;
import com.lx.util.FilmManager;
import com.sun.xml.internal.ws.server.ServerRtException;

import java.time.LocalDate;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

/**
 * @author c先生
 * @date 2022年03月31日 下午 7:45:14
 * @describe
 */

public class FilmMain {
    public static void main(String[] args) {
        FilmManager fm = new FilmManager();
        Scanner sc = new Scanner(System.in);
        fm.init();//初始化
        while (true) {
            System.out.println("----------功能: ");
            System.out.println("1.展示旗下影院的信息");
            System.out.println("2.展示旗下影院放映的影片信息");//两个影院在播放同一个电影
            System.out.println("3.根据影院的名称查看旗下放映的影片");
            System.out.println("4.新增一个影片，添加在对应的影院");
            System.out.println("5.下架一个影片(可选择所有下架和针对性下架，输入all表示下架所有)");
            System.out.println("6.根据题材查询影片");
            System.out.println("7.根据主演查询影片");
            int key = sc.nextInt();
            switch (key){
                case 1:
                    fm.showAllCinema();
                    break;
                case 2:
                    HashSet<Film> films = fm.showAllFilm();
                    for (Film film : films) {
                        System.out.println(film.toString());
                    }
                    break;
                case 3:
                    System.out.println("所有影院名称如下：");
                    List<String> strings = fm.showAllCinemaName();
                    for (String string : strings) {
                        System.out.print(string+" ");
                    }
                    System.out.println();
                    System.out.println("请选择你要查询的影院名称：");
                    fm.showAllFilmByCinemaName(sc.next());
                    break;
                case 4:
                    System.out.println("请输入影片名称：");
                    String addFimlName = sc.next();
                    if(fm.existFilm(addFimlName)!=null){
                        System.out.println("此影片已经存在！");
                    }else {
                        System.out.println("请输入电影类型");
                        String addfilmType = sc.next();
                        System.out.println("请输入时长");
                        String addfilmTime = sc.next();
                        System.out.println("请输入主演");
                        String addfilmActor = sc.next();
                        System.out.println("请输入简介");
                        String addfilmIntro = sc.next();
                        System.out.println("请输入上映时间");
                        LocalDate addpublicationTime = LocalDate.of(sc.nextInt(),sc.nextInt(),sc.nextInt());
                        Film addFilm = new Film(null,addFimlName,addfilmType,addfilmTime,addfilmActor,addfilmIntro,addpublicationTime);
                        System.out.println("请选择要上映的影院(输入all表示全部上映)：");
                        List<String> strings2 = fm.showAllCinemaName();
                        for (String string : strings2) {
                            System.out.print(string+" ");
                        }
                        String cinemaNameStr = sc.next();
                        boolean flag = fm.addFilmAndPublication(addFilm,cinemaNameStr);
                        if(flag){
                            System.out.println("添加成功！");
                        }else {
                            System.out.println("添加失败！");
                        }
                    }
                    break;
                case 5:
                    System.out.println("请输入影片名称：");
                    String addFimlName2 = sc.next();
                    if(fm.existFilm(addFimlName2)==null) {
                        System.out.println("此影片不存在！");
                    }else {
                        System.out.println("请输入要下架的影院名称：");
                        String cinemaNameStr = sc.next();
                        boolean flag = fm.removeFilm(addFimlName2,cinemaNameStr);
                        if(flag){
                            System.out.println("下架成功！");
                        }else {
                            System.out.println("下架失败！");
                        }
                    }

                    break;
                case 6:
                    System.out.println("请输入电影类型：");
                    Set<Film> filmList = fm.findFilmByType(sc.next());
                    for (Film film : filmList) {
                        System.out.println(film.toString());
                    }
                    break;
                case 7:
                    break;
            }

        }
    }
}
